#include <iostream>

using namespace std;

string to_n_scale(int num, int n){
    string res;
    if(num == 0) return "0";
    while(num){
        res += (num % n) + '0';
        num /= n;
    }
    return res;
}
bool is_paliandrome(const string& str){
    int left = 0, right = str.size() - 1;
    while(left < right){
        if(str[left] != str[right]) return false;
        left++;
        right--;
    }
    return true;
}
int main(){
    int n; cin >> n;
    int start; cin >> start;
    start++;
    while(true){
        // 2~10 进制字符串
        int count = 0;
        for(int i = 2; i <= 10; ++i){
            string str = to_n_scale(start, i);
            if(is_paliandrome(str)) count++;
            if(count == 2) {
                cout << start << endl;
                --n;
                if(n == 0) return 0;
                break;
            }
        }
        start++;
    }
}